package com.example.rabbitmq.limit;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @author weiyx
 * @date 2021-01-10
 */
public class producer {

    public static void main(String[] args) throws IOException, TimeoutException {

        //1,创建工厂
        ConnectionFactory connectionFactory = new ConnectionFactory();
        connectionFactory.setHost("127.0.0.1");
        connectionFactory.setPort(5672);
        connectionFactory.setUsername("guest");
        connectionFactory.setPassword("guest");
        //2, 获取连接
        Connection connection = connectionFactory.newConnection();
        //3, 通过connection创建一个channel
        Channel channel = connection.createChannel();

        String exchangeName = "test_qos_exchange";
        String routingKey = "qos.save";

        //5, 发送消息
        String msg = "hello rabbitmq send retuen message!";
        for (int i = 0; i < 5; i++) {
            channel.basicPublish(exchangeName, routingKey, true,null, msg.getBytes());
        }
//        channel.close();
//        connection.close();

    }



















}
